<?php
/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Html;
use yii\bootstrap\NavBar;
use yii\bootstrap\Nav;
use frontend\modules\yii2\widgets\layouts\dockerdoc\assets\DockerDocAsset;
\frontend\assets\AppAsset::register($this);
DockerDocAsset::register($this);
$isDockerActive = "active";
$this->beginPage();
echo "<!doctype html>";
echo "<html lang='zh-CN'>";
// head -----------------------------------------------
echo Html::beginTag("head");
$this->registerMetaTag(["charset" => "utf-8"]);
$this->registerMetaTag(["http-equiv" => "X-UA-Compatible", "content" => "IE=edge"]);
$this->registerMetaTag(["name" => "viewport", "content" => "width=device-width, initial-scale=1"]);
//$this->registerLinkTag(["rel" => "icon", "href" =>"https://www.yiichina.com/favicon.ico?v=1528501659"]);
$this->registerLinkTag(["rel" => "icon", "href" =>"/favicon.ico"]);
$this->registerCsrfMetaTags();
$this->registerMetaTag(['name' => 'author','content' => 'chenzhiwei']);

echo Html::tag("title", Html::encode($this->title) . "-Yii2框架最新中文教程");
$this->head();
echo Html::endTag("head");
// head done -----------------------------------------------

// body -----------------------------------------------
echo "<body>";
$this->beginBody();

// nav bar
$controllerId = Yii::$app->controller->id == "site" ? Yii::$app->controller->action->id : Yii::$app->controller->id;

//var_dump($controllerId);die;
NavBar::begin([
    "brandImage" => '/images/logo.png',
    "options" => ["class" => "navbar navbar-inverse navbar-fixed-top"],
    "containerOptions" => ["id" => "navbar", "class" => "row"]
]);
$navs = [
    "left" => [
        ["label" => "Home", "controller" => "home", "url" => "/"],
        ["label" => "Bootstrap3", "controller" => "bootstrap3", "url" => "/bootstrap3"],
        ["label" => "Docs", "controller" => "docs", "url" => "/docs"],
        ["label" => "Codelab", "controller" => "codelab", "url" => "/codelab"],
       // ["label" => "Docker Tools", "controller" => "docker", "url" => "/docker"],
        ["label" => "Template", "controller" => "template", "url" => "/template"],
//        ["label" => "视频", "controller" => "video", "url" => "/video"],
    ],
    "right" => [
        ["label" => "Contact", "controller" => "contact", "url" => "/contact"],
    ]
];
$leftNavs = array_map(function($item) use ($controllerId){
    $item["linkOptions"] = ["class" => $controllerId == $item["controller"] ? "active" : ""];
    return $item;
},$navs["left"]);
$rightNavs = array_map(function($item) use ($controllerId){
    $item["linkOptions"] = ["class" => $controllerId == $item["controller"] ? "active" : ""];
    return $item;
},$navs["right"]);

echo Nav::widget([
    "items" => $leftNavs,
    "options" => ["class" => "nav navbar-nav navbar-left hidden-xs"],
]);
echo Nav::widget([
    "items" => $rightNavs,
    "options" => ["class" => "nav navbar-nav navbar-right hidden-xs"],
]);

if(Yii::$app->controller->id == "site"){
    echo Nav::widget([
        "items" => array_map(function($item) use ($controllerId){
            $item["linkOptions"] = [];
            $item["options"] = ["class" => "col-xs-4"];
            return $item;
        }, array_merge($leftNavs, $rightNavs)),
        "options" => ["class" => " hidden-lg hidden-md hidden-sm", "style" => "white-space:nowrap;"],
    ]);
}


NavBar::end();
// phone nav bar

//var_dump(__DIR__ . "/" . Yii::$app->controller->id . ".php");die;
// article content
if(file_exists(__DIR__ . "/" . Yii::$app->controller->id . ".php")){
    require Yii::$app->controller->id . ".php";
    $this->registerJs('$(".navbar-header button").attr("data-target", "#sidebar");', \yii\web\View::POS_READY);
} else {
    echo $content;
}
//switch ($controllerId){
//    case "bootstrap3":
//        require "bootstrap.php";
//        $this->registerJs('$(".navbar-header button").attr("data-target", "#sidebar");', \yii\web\View::POS_READY);
//        break;
//    case "docs":
//        require "docs.php";
//        $this->registerJs('$(".navbar-header button").attr("data-target", "#sidebar");', \yii\web\View::POS_READY);
//        break;
//    case "codelab":
//        require "codelab.php";
//        $this->registerJs('$(".navbar-header button").attr("data-target", "#sidebar");', \yii\web\View::POS_READY);
//        break;
//    default:
//        echo $content;
//}

$this->endBody();
echo "</body>";
echo "</html>";
$this->endPage();